<template><div></div> </template>
<script>
import { newlogin } from '@/api/login.js'
import { setToken } from '@/utils/auth.js'
import store from '@/store'
export default {
  data() {
    return {}
  },
  methods: {
    handleLogin() {
      const url = this.$route.query.url
      const param = { userId: this.$route.query.sid }
      newlogin(param).then(res => {
        if (res.code === 0) {
          setToken(res.data)
          store.commit('SET_TOKEN', res.data)
          this.$router.push({ path: url })
        } else {
          this.$message.error('登录失败！' + res.msg)
        }
      })
    }
  },
  mounted() {
    if (
      this.$route.query.sid === undefined ||
      this.$route.query.url === undefined
    ) {
      this.$message.error('登录失败！url参数错误')
    } else {
      this.handleLogin()
    }
  }
}
</script>
